package com.joysuch.wwyt.workflow.controller;


import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.enums.Status;
import com.joysuch.wwyt.workflow.entity.WorkflowTaskExportTemplate;
import com.joysuch.wwyt.workflow.service.WorkflowTaskExportTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jwk
 * @since 2021-07-23
 */
@RestController
@RequestMapping("/workflow/export")
@Api(tags = "流程导出")
public class WorkflowTaskExportTemplateController {

    @Autowired
    private WorkflowTaskExportTemplateService workflowTaskExportTemplateService;

    @PostMapping("/template/saveOrUpdate")
    @ApiOperation(value = "保存或修改")
    public ResultBean saveOrUpdate(@RequestBody WorkflowTaskExportTemplate workflowTaskExportTemplate) {
        boolean isSuccess = workflowTaskExportTemplateService.saveOrUpdate(workflowTaskExportTemplate);
        if (isSuccess) {
            return ResultBean.success(workflowTaskExportTemplate.getId());
        } else {
            return ResultBean.fail(Status.FAILED);
        }
    }

    @PostMapping("/template/delete")
    @ApiOperation(value = "删除")
    public ResultBean delete(Long noticeId) {
        WorkflowTaskExportTemplate template = new WorkflowTaskExportTemplate();
        template.setDeleteFlag("1");
        template.setId(noticeId);
        workflowTaskExportTemplateService.updateById(template);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("/template/list")
    @ApiOperation(value = "列表")
    public ResultBean list(Long processId) {
        List<WorkflowTaskExportTemplate> list = workflowTaskExportTemplateService.findList(processId);
        return ResultBean.success(list);
    }

}

